<?php

	function post($url, $params = array(), $port = 0) {
		if (!$url) {
			return false;
		}
		if (!function_exists('curl_init')) {
			return false;
		}
		$ch = curl_init();
		curl_setopt($ch, CURLOPT_URL, $url);
       		 if($port) {
		    curl_setopt($ch, CURLOPT_PORT, $port);
        	}
		curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 1);
		curl_setopt($ch, CURLOPT_TIMEOUT, 2);
		curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
		curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
		curl_setopt($ch, CURLOPT_POST, true);
		curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
		curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
		$result = curl_exec($ch);
		curl_close($ch);
		return $result;
	}	
	
	
	/**
	 * http get请求
	 * @param   string  url     请求的url
	 * @param   int     port    端口
	 * @return  string  result  请求结果，失败返回false
	 */
	function get($url, $port = 80) {
		if (!$url) {
			return false;
		}
		if (!function_exists('curl_init')) {
			return false;
		}
		$ch = curl_init();
		curl_setopt($ch, CURLOPT_URL, $url);
		curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, self::$connect_timeout);
		curl_setopt($ch, CURLOPT_TIMEOUT, self::$curl_timeout);
		//curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
		//curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
		// 对认证证书来源的检查，0表示阻止对证书的合法性的检查。
		curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
		// 从证书中检查SSL加密算法是否存在
		curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
		curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
		$result = curl_exec($ch);
		if (!$result) {
			$errmsg = curl_error($ch);
			self::setError($errmsg);
		}
		self::setInfo(curl_getinfo($ch));
		curl_close($ch);
		return $result;
	}


	/*监听demo频道，打印收到的信息*/
	function process($redis, $chan, $msg){
    		//var_dump($msg);

		$request = "http://192.168.16.216/p/user/groupLogic";
		$param = array("json" => $msg);
		$ret = post($request, $param);
	}

	$redis = new Redis();
	$res = $redis->connect('192.168.16.213', '6379');
	$redis->setOption(Redis::OPT_READ_TIMEOUT, -1);
	$redis->subscribe(array('group'), 'process');
